<template>
  <div class="defectFixedIndex">
    <userHeader />
    <div class="breadClum">
      <span>
        <router-link :to="{path:'/pageIndex'}">   <a class="bread1">当前位置：首页  >  </a></router-link>
        <router-link :to="{path:'/comment'}">   <a class="bread2">内控评价  ></a></router-link>
            <a  class="bread2">缺陷整改</a>
      </span>
    </div>
    <div class="navList">
      <span  @click.stop="editor">
       编辑
      </span>
      <span @click.stop="saveBtn">
      保存
      </span>
      <div class="custmerTips">
        <ul>
          <li>
            <span class="hasDone"></span>
            <b>已完成</b>
          </li>
        </ul>
      </div>
    </div>
    <!--:style="{'max-height':`${height}`}"-->
    <!--:max-height="600"-->
    <el-table
      :data="tableData"
      :row-class-name="tableRowClassName2"
      :cell-class-name="cell"
      stripe=""
      ref="tableData3"
      v-loading="loading"
      style="width:100%"
      :height="height"
    >
      <!--:style="{'height':`${height}`}"-->
      <el-table-column
        label="操作"
        prop="process_name"
        fixed
      >
        <template slot-scope="scope">
          <el-checkbox @change="checked => selectComment(checked, scope.row)"  :disabled="!(user_id==scope.row.section_principal_id||user_id==scope.row.evaluator_id||user_id==scope.row.mend_principal[0].id||(scope.row.mend_principal[1]&&user_id==scope.row.mend_principal[1].id)||(user_id==scope.row.guidance_id))" v-model="scope.row.disabled==1"></el-checkbox>
        </template>
      </el-table-column>
      <el-table-column
        label="评价流程"
        prop="process_name"
        fixed
      >
        <template slot-scope="scope">
          {{scope.row.process_name}}
        </template>
      </el-table-column>
      <el-table-column
        label="评价内容"
        prop="evaluation_content"
      >
        <template slot-scope="scope">
          {{scope.row.evaluation_content}}
        </template>
      </el-table-column>
      <el-table-column
        label="评价标准"
        prop="evaluation_criterion"
        width="300"
      >
      </el-table-column>
      <el-table-column
        label="评价结论"
        prop="defect_title"
        width="200"
      >
      </el-table-column>
      <el-table-column
        prop="defect_source"
        label="缺陷来源"
      >
      </el-table-column>
      <el-table-column
        label="缺陷性质"
        prop="defect_property_text"
      >
      </el-table-column>
      <el-table-column
        label="缺陷影响结果"
        prop="defect_impact_results"
      >
      </el-table-column>
      <el-table-column
        label="改进建议"
        prop="suggestions_improvement"
      >
      </el-table-column>
      <el-table-column
        label="责任部门"
        prop="section_name"
      >
      </el-table-column>
      <el-table-column
        label="责任部门负责人"
        prop="section_principal"

      >
      </el-table-column>
      <el-table-column
        label="整改任务分配"
        prop="dis_current_time"
      >
        <el-table-column
          label="缺陷确认"
          prop="defect_state"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.disabled==1&&disabled&&scope.row.compile_rectificationplan_state[0]==0">
              <p  >
                  <span @click.stop="toggleAdpaIdentify(scope.$index,1)">
                     <b :class="{'e-wrong':true,'e-wrong-active': scope.row.defect_state === '2' }"></b>

                  </span>
                <span @click.stop="toggleAdpaIdentify(scope.$index,2)">
                      <b :class="{'e-right-active':scope.row.defect_state === '1', 'e-right':true}" ></b>
                    </span>
              </p>
            </div>
            <div v-else>
              <p >
                 <span >
                     <b :class="{'e-wrong':true,'e-wrong-active': scope.row.defect_state === '2' }"></b>
                   <!--<b class="e-wrong-disActive e-wrong " v-else></b>-->
                  </span>
                <span >
                      <b :class="{'e-right-active':scope.row.defect_state === '1', 'e-right':true}" ></b>
                    </span>

              </p>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="沟通意见"
          prop="communication_ideas"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.disabled==1&&disabled&&scope.row.compile_rectificationplan_state[0]==0">
              <div >
                <el-input type="textarea" :rows="4" v-model="scope.row.communication_ideas"></el-input>
              </div>
            </div>
            <div v-else>
              {{scope.row.communication_ideas}}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="整改负责人"
          prop="mend_principal"
          width="100"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.disabled==1&&disabled&&scope.row.compile_rectificationplan_state[0]==0">
              <div class="mend_principal_scope">
                <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell" @click.stop="showFormMenbertrue(scope.row,true,scope.row.index,index)">
                  {{scope.row.mend_principal[index].name}}
                </div>
              </div>
            </div>
            <div v-else>
              <div class="mend_principal_scope">
                <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell" >
                  <div>
                    {{scope.row.mend_principal[index].name}}
                  </div>

                </div>
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column
        label="编制整改计划"
      >
        <el-table-column
          label="缺陷原因分析"
          prop="defect_reason_analysis"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.reason_analysis==1">
              <div class="mend_principal_scope">
                <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">

                  <div v-if="scope.row.review_rectificationplan_state[index]==0&&!step4&&scope.row.mend_principal[index].id==user_id">
                    <!--:disabled="scope.row.defect_reason[index]!=1"-->

                    <el-input type="textarea"  v-model="scope.row.defect_reason_analysis[index]" ></el-input>
                  </div>
                  <div v-else class="asdllllllll">
                    {{scope.row.defect_reason_analysis[index]}}
                  </div>
                </div>
              </div>
            </div>
            <div v-else>
              <div class="mend_principal_scope">
                <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
                  {{scope.row.defect_reason_analysis[index]}}
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="整改计划"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.reason_analysis==1">
              <div class="mend_principal_scope">
                <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
                  <div v-if="scope.row.review_rectificationplan_state[index]==0&&!step4&&scope.row.mend_principal[index].id==user_id">
                    <!--:disabled="scope.row.defect_reason[index]!=1"-->
                    <el-input type="textarea"  v-model="scope.row.rectification_measures[index]" ></el-input>
                  </div>
                  <div v-else>
                    {{scope.row.rectification_measures[index]}}
                  </div>
                </div>
              </div>
            </div>
            <div class="mend_principal_scope" v-else>
              <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
                {{scope.row.rectification_measures[index]}}
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="计划完成时间"
          prop="evaluation_finishtime"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.reason_analysis==1">
              <div class="mend_principal_scope">
                <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
                  <div class="mend-e-datePicker"  v-if="scope.row.review_rectificationplan_state[index]==0&&!step4&&scope.row.mend_principal[index].id==user_id">
                    <!--v-if="scope.row.rectification_measures[index]==0"-->
                    <!--{{scope.row.evaluation_finishtime[index]}}-->
                    <!--{{newDateTime(parseInt(scope.row.evaluation_finishtime[index]))}}-->
                    <!--:disabled="scope.row.defect_reason[index]!=1"-->
                    <el-date-picker
                      v-model="scope.row.evaluation_finishtime[index]"
                      type="date"
                      :picker-options="pickerOptions1"
                      @change="logTime"
                      placeholder="选择日期">
                    </el-date-picker>
                  </div>
                  <div v-else>
                    {{scope.row.evaluation_finishtime[index]}}
                  </div>
                </div>
              </div>
            </div>
            <div v-else>
              <div class="mend_principal_scope">
                <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
                  {{editorStart_time(scope.row.evaluation_finishtime[index])}}
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column
        label="复核整改计划"
      >
        <!--rectification_state-->
        <template slot-scope="scope">
          <!--当前编制整改计划已经完成-->
          <div class="mend_principal_scope ssss" v-if="scope.row.review_opinions==1">
            <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
              <div  v-if="(scope.row.compile_rectificationplan_state[index]==1&&scope.row.compile_rectificationresult_state[index]==0&&user_id==scope.row.section_principal_id&&scope.row.reCheck==1&&scope.row.mend_principal[index].id!=scope.row.section_principal_id)||(
                    scope.row.compile_rectificationplan_state[index]==1&&scope.row.compile_rectificationresult_state[index]==0&&user_id==scope.row.guidance_id&&scope.row.reCheck==1&&scope.row.mend_principal[index].id==scope.row.section_principal_id
                )">
                <p>
                  <span @click.stop="toggleAdpaIdentifyshenhe(scope.$index,1,index)">

                     <b :class="{'e-wrong':true,'e-wrong-active': scope.row.rectification_state[index] === '2' }"></b>
                  </span>
                  <span @click.stop="toggleAdpaIdentifyshenhe(scope.$index,2,index)">
                      <b :class="{'e-right-active':scope.row.rectification_state[index] === '1', 'e-right':true}" ></b>
                    </span>
                </p>
              </div>
              <div  v-else-if="scope.row.compile_rectificationplan_state[index]==1">
                <p  >
                  <span >
                     <b :class="{'e-wrong':true,'e-wrong-active': scope.row.rectification_state[index] === '2' }"></b>
                  </span>
                  <span >
                      <b :class="{'e-right-active':scope.row.rectification_state[index] === '1', 'e-right':true}" ></b>
                  </span>
                </p>
              </div>
              <div v-else class="asdadad">
                <p></p>
              </div>
            </div>
          </div>
          <div class="mend_principal_scope" v-if="scope.row.review_opinions==1&&scope.row.rectification_resul==1">
            <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
              <div >
                <p  >
                  <span >
                     <b :class="{'e-wrong':true,'e-wrong-active': scope.row.rectification_state[index] === '2' }"></b>
                  </span>
                  <span >
                      <b :class="{'e-right-active':scope.row.rectification_state[index] === '1', 'e-right':true}" ></b>
                    </span>
                </p>
              </div>
            </div>
          </div>
          <div class="mend_principal_scope" v-if="scope.row.review_opinions==1&&scope.row.rectification_resul==1">
            <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
              <div > </div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="整改结果"
      >
        <el-table-column
          label="整改结果"
          prop="rectification_results"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.has_analysis==1&&!step4">
              <!-- this.row.reason_analysis =1;
                          this.step2=true;
                          this.step4=false;
                          this.row.defect_reason[1]=1;-->
              <div class="mend_principal_scope">
                <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
                  <div v-if="scope.row.rectification_results_input[index]==1&&scope.row.review_rectificationplan_state[index]==1&&user_id==scope.row.mend_principal[index].id">
                    <!--{{scope.row.review_rectificationplan_state[index]}}-->
                    <el-input type="textarea"  v-model="scope.row.rectification_results[index]" :disabled="scope.row.rectification_results_input[index]!=1"></el-input>
                  </div>
                  <div v-else>
                    {{scope.row.rectification_results[index]}}
                  </div>
                </div>
              </div>
            </div>
            <div v-else>
              <div class="mend_principal_scope">
                <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
                  {{scope.row.rectification_results[index]}}
                </div>
              </div>
            </div>
          </template>

        </el-table-column>
        <el-table-column
          label="未整改原因及措施"
          prop="reasons_measures"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.has_analysis==1&&!step4">
              <div class="mend_principal_scope">

                <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
                  <div v-if="scope.row.rectification_results_input[index]==1&&user_id==scope.row.mend_principal[index].id">
                    <el-input type="textarea"  v-model="scope.row.reasons_measures[index]" :disabled="scope.row.rectification_results_input[index]!=1"></el-input>
                  </div>
                  <div v-else>
                    {{scope.row.reasons_measures[index]}}
                  </div>
                </div>
                <!--<div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">-->
                <!--<el-input type="textarea"  v-model="scope.row.reasons_measures[index]" :disabled="scope.row.defect_reason[index]!=1"></el-input>-->
                <!--</div>-->
              </div>
            </div>
            <div v-else>
              <div class="mend_principal_scope">
                <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
                  {{scope.row.reasons_measures[index]}}
                </div>
              </div>
            </div>
          </template>

          <!--<template slot-scope="scope">-->
          <!--<div class="mend_principal_scope">-->
          <!--<div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">-->

          <!--</div>-->
          <!--</div>-->
          <!--</template>-->
        </el-table-column>
      </el-table-column>
      <el-table-column
        label="落实整改结果"
      >
        <el-table-column
          label="整改结果确认"
        >
          <template slot-scope="scope">
            <!--当前编制整改计划已经完成-->
            <div class="mend_principal_scope" v-if="scope.row.review_opinions==1">
              <!--this.row.review_opinions==1  this.row.compile_rectificationresult_state[0]==1&&this.user_id==this.row.evaluator_id&&this.row.reCheck==1&&
              this.row.compile_rectificationresult_state[0]==1
              -->
              <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
                <div  v-if="scope.row.compile_rectificationresult_state[index]==1&&user_id==scope.row.evaluator_id&&scope.row.reCheck==1">
                  <p  >
                  <span @click.stop="toggleAdpaIdentifycomment(scope.$index,1,index)">
                     <b :class="{'e-wrong':true,'e-wrong-active': scope.row.def_rec_state[index] === '2' }"></b>
                  </span>
                    <span @click.stop="toggleAdpaIdentifycomment(scope.$index,2,index)">
                      <b :class="{'e-right-active':scope.row.def_rec_state[index] === '1', 'e-right':true}" ></b>
                    </span>
                  </p>
                </div>
                <!--整改结果状态第四步的状态 compile_rectificationresult_state
                -->
                <div  v-else-if="scope.row.compile_rectificationresult_state[index]==1">
                  <p  >
                  <span >
                     <b :class="{'e-wrong':true,'e-wrong-active': scope.row.def_rec_state[index] === '2' }"></b>
                  </span>
                    <span >
                      <b :class="{'e-right-active':scope.row.def_rec_state[index] === '1', 'e-right':true}" ></b>
                    </span>
                  </p>
                </div>
                <!--<div v-else-if="scope.row.compile_rectificationresult_state[index]==1&&(scope.row.implement_rectificationresult_state[index]==0)">-->

                <!--</div>-->
                <!--<div v-else class="asdadad">-->
                <!--<p>-->

                <!--</p>-->
                <!--</div>-->
              </div>
            </div>
            <div class="mend_principal_scope" v-if="scope.row.review_opinions==1&&scope.row.rectification_resul==1">
              <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
                <div >
                  <p  >
                  <span >
                     <b :class="{'e-wrong':true,'e-wrong-active': scope.row.def_rec_state[index] === '2' }"></b>
                  </span>
                    <span >
                      <b :class="{'e-right-active':scope.row.def_rec_state[index] === '1', 'e-right':true}" ></b>
                    </span>
                  </p>
                </div>
              </div>
            </div>
            <!--<div class="mend_principal_scope" v-if="scope.row.review_opinions==1">-->
            <!--<div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">-->
            <!--<div >-->
            <!--</div>-->
            <!--</div>-->
            <!--</div>-->
          </template>
        </el-table-column>
        <el-table-column
          label="落实意见"
          prop="implementation_opinions"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.review_opinions==1&&step5">
              <div class="mend_principal_scope">
                <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
                  <div v-if="scope.row.confirm_result[index]==1&&scope.row.evaluator_id==user_id">
                    <el-input type="textarea"  v-model="scope.row.implementation_opinions[index]" :disabled="scope.row.confirm_result[index]!=1"></el-input>
                  </div>
                  <div v-else>
                    {{scope.row.implementation_opinions[index]}}
                  </div>
                </div>
              </div>
            </div>
            <div v-else class="step5">
              <div class="mend_principal_scope">
                <div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">
                  {{scope.row.implementation_opinions[index]}}
                </div>
              </div>
            </div>
          </template>
          <!--<template slot-scope="scope">-->
          <!--<div class="mend_principal_scope">-->
          <!--<div v-for="(item,index) in scope.row.defect_source" :class="{'hasOne':scope.row.defect_source.length==1,'hasTwo':scope.row.defect_source.length==2}" class="mend_principal_cell">-->

          <!--</div>-->
          <!--</div>-->
          <!--</template>-->
        </el-table-column>
      </el-table-column>
    </el-table>
    <el-dialog title="整改负责人" :visible.sync="dialogFormVisible3" class="e-dialoge-editor">
      <el-form :model="formMenber" ref="formMenber">
        <el-table
          ref="multipleTable2"
          :data="tableData2"
          :row-class-name="tableRowClassName"

          style="width: 100%"
          border
        >
          <el-table-column
            label="用户名"
            prop="user_name"
          >
          </el-table-column>
          <el-table-column
            label="用户描述"
            prop="real_name"
          >
          </el-table-column>
          <el-table-column
            label="选择"
          >
            <template slot-scope="scope">
              <el-form-item  >
                <el-switch
                  @change="changeSwitch(scope.row.index,scope.row.isActive)"
                  v-model="scope.row.isActive"
                  active-color="#8cc34b"
                  inactive-color="#ff4949"
                  active-value="1"
                  inactive-value="0"
                >
                </el-switch>
              </el-form-item>
            </template>
          </el-table-column>
        </el-table>
        <div  class="dialog-footer">
          <el-button @click="dialogFormVisible3 = false">取 消</el-button>
          <el-button type="primary" @click="confirmEditor('formMenber')">确 定</el-button>
        </div>
      </el-form>
    </el-dialog>
    <el-pagination
      :page-count=pageSize
      layout="total,prev, pager, next, jumper"
      :current-page.sync="currentPage"
      @current-change="currentChange"
    >
    </el-pagination>
  </div>
</template>
<script>
  import {mapState} from 'vuex';
  import userHeader from '@/components/header.vue'
  import {formatDateTime,formatgetTime} from '@/utils/index.js'
  export default({
    computed:{
      ...mapState({
        user_id:state=>state.app.loginState.user_id||sessionStorage.getItem('user_id'),
        height:state=>sessionStorage.getItem('height')||state.app.height,
      }),
      editorStart_time(){
        return function (selectTypeArray) {
          if(typeof selectTypeArray =="object"){
            return formatgetTime(selectTypeArray)
          }else{
            return selectTypeArray
          }
        }
      },
      newDateTime(){
        return function (selectTypeArray) {
          return new Date(selectTypeArray)
        }
      }
    },
    data(){
      var checkCommunication =(rule, value, callback) => {
        if(this.commentTypeForm.defect_state==undefined){
          return callback('请确认缺陷')
        }else{
          callback()
        }
      };
      return {
        tableDataUserName:[],
        step1:true,
        step2:false,
        step3:false,
        step4:true,
        step5:false,
        page:1,
        pageSize:1,
        total:0,
        currentPage:1,
        pageCount:0,
        rowIndex:'',
        index:'',
        clickIndex:'',
        changeIndex:'',
        tableData:[],
        tableData2:[],
        mend_principal:[],
        selectValue:1,
        commentDesign:['设计评价整改','执行评价整改'],
        dialogFormVisible3:false,
        dialogFormVisible:false,
        formMenber:{},
        formLabelWidth:'100px',
        commentTypeForm:{},
        multipleSelection:[],
        disabled:false,
        row:'',
        userData:[],
        oaMessage:[],
        loading:true,
        defect_source:['设计缺陷','执行缺陷'],
        pickerOptions1: {
          disabledDate(time) {
            return time.getTime() < Date.now() - 8.64e7;
          },
        },
        //添加评价计划验证
        commentType:{
          defect_state:[
            { required: true,validator:checkCommunication}
          ],
        },
        message:[],
      }
    },
    components:{
      userHeader,
    },
    methods:{
      getUserName3(val){
        if(this.tableDataUserName){
          for(var i in this.tableDataUserName){
            console.log(this.tableDataUserName[i].user_id)
            if(this.tableDataUserName[i].user_id ==val){
              return this.tableDataUserName[i].user_name
            }
          }
        }
      },
      getMenber(){
        this.axios.get('/api/v1/flow/participantusers/'+`${this.company_id}`)
          .then((res)=>{
            if(res.data.code==0){
              this.tableDataUserName=res.data.data;
            }
//            console.log(this.tableData2)
          }).catch((res)=>{
          console.log(res)
          this.$alert(res)
        })
      },
      keyDown(val){
        console.log(val)
      },
      logTime(val){
        return formatDateTime(val)
      },
      //分页状态改变
      currentChange(val){
        this.page =val;
        this.loading =true;
        this.initData(this.page)
      },
      //选择评价点
      selectComment(val,row){
        this.rowIndex =row.index;
        for(var i in this.tableData){
          this.tableData[i].disabled="0";
          this.tableData[i].reCheck=0;
          this.tableData[i].rectification_results_input=[];
          this.tableData[i].confirm_result=[];
        };
        if(val){
          this.row =row;
          this.step1=true;
          this.step2=false;
          this.step3=false;
          this.step4=true;
          this.step5=false;
          row.disabled = "1";
          console.log(row.rectification_measures[0]);
          console.log(row.review_rectificationplan_state);
//            编制整改计划的判断条件  第二步
          if(row.rectification_measures[0]){
            row.reCheck=1;
            row.has_analysis=1;
//              第三步 复核整改计划的判断
            // 复核整改计划第一步已经完成 第二步不存在或者没有开始
            if(row.review_rectificationplan_state[0]){
//                        this.step3=true;
              if(row.review_rectificationplan_state[0]>=1&&row.mend_principal[0].id==this.user_id){
                row.rectification_results_input[0]=1;
              };
              //第五步操作的附加判断
              if(row.evaluator_id==this.user_id){
                if(row.compile_rectificationresult_state[0]==1){
                  if(row.compile_rectificationresult_state[0]==1
                  ){
                    //第一个评价计划可执行
                    row.confirm_result[0] =1;
                  }else if(row.compile_rectificationresult_state[0]==1||row.compile_rectificationresult_state[1]=='undefined'){
                    row.confirm_result[0] =1;
                  }
                }
              }

              if(row.compile_rectificationresult_state[0]==1&&row.evaluator_id[0].id==this.user_id){
                //                      前四步都已经完成第五步可以操作
                row.confirm_result[0]=1;
              }
              // 复核整改计划第二步都完成
            }else if(row.review_rectificationplan_state[0]){
              if(row.review_rectificationplan_state[0]>=1&&row.mend_principal[0].id==this.user_id){
                row.rectification_results_input[1]=1;
                row.rectification_results_input[0]=1;
                if(row.compile_rectificationresult_state[0]==1){
                  row.confirm_result[0]=1
                };
//                      this.step4=false;
              }else  if(row.review_rectificationplan_state[0]>=1 ){
                if(row.mend_principal[0].id==this.user_id){
                  row.rectification_results_input[0]=1;
                  if(row.compile_rectificationresult_state[0]==1){
                    row.confirm_result[0]=1;
                  }
                }
              }
              // 复核整改计划第二步完成复核整改计划第一步未完成
            }else if(!row.review_rectificationplan_state[0]){
//                  评价人员id 相同状态
            }else if(row.evaluator_id==this.user_id){
              if(row.compile_rectificationresult_state[0]==1){
                if(row.compile_rectificationresult_state[0]==1
                ){
                  //第一个评价计划可执行
                  row.confirm_result[0] =1;
                }else if(
                  row.compile_rectificationresult_state[0]==0){
                  row.confirm_result[1] =1;
                }
              }
            }
          }
        }else {
          row.disabled ="0";
          row.disabled =0;
          this.step1=true;
          this.step2=false;
          this.step3=false;
          this.step4=true;
          this.step5=false;
        }
        console.log(row)
      },

      editor(){
        //不同阶段操作区间不一样
        //责任部门负责人  第一区间和第三区间
        //第一区间
        console.log(this.row);
        if(this.row.section_principal_id ==this.user_id&&this.row.task_allocation_state==0){
            //第一步操作
          for(var i in this.tableData){
            if(this.tableData[i].disabled=="1"){
              this.disabled =true;
              return false;
            }
          }
        }
        //此时已经指定好相关的整改人员  第二区间 操作编制整改计划 从编制整改计划（第二步）开始执行
        else if(this.row.mend_principal&&this.row.task_allocation_state==1){
          console.log(this.row.review_rectificationplan_state[0])
            if(this.row.review_rectificationplan_state[0]==0){
              //只有一条数据  编制整改计划 第二步未完成
              this.row.reason_analysis =1;
              this.step2=true;
              this.step4=false;
            }else{
                //第二步已经完成  第三步  第四步 第五步
//              alert(10);
              if(this.row.review_rectificationplan_state[0]==0||this.row.review_rectificationplan_state[0]==2
              &&(!this.row.compile_rectificationresult_state[0])&&(!this.row.implement_rectificationresult_state)){
                  //第三步复核整改操作
//                  alert(11);
                  this.step2=true;
                  this.step4 =false;

              }
              if(this.row.mend_principal[0].id ==this.user_id){
                  //当前账号是整改负责人时候
                this.row.defect_reason[0]=1;
                this.step4 =false;
                this.step2=false;

              }
              if(this.row.evaluator_id ==this.user_id&&this.row.compile_rectificationresult_state[0]==1){
                this.step5 =true;
              }
            }
        }
        else if(this.row.evaluator_id==this.user_id&&this.row.compile_rectificationresult_state[0]==1
        ){
//          第五步评价人员的设置值
          this.step5=true;
          console.log('编辑 第五步的操作');
          this.row.confirm_resuklt=1;
          console.log(this.row)
//          两个整改结果下
         if(this.row.compile_rectificationresult_state[0]==1
            &&this.row.review_rectificationplan_state[0]==1
            &&this.row.compile_rectificationresult_state[1]==undefined){
            this.row.confirm_result[0]=1;
            console.log(this.row.confirm_result);
          }
        }
        //编制整改计划完成
        //   一个或者两个
        //   前两步操作不可修改
        else if(this.row.review_rectificationplan_state[0]==1){
//              设计评价的编制整改计划已经完成
          this.tableData[this.rowIndex].review_opinions =1;
          this.step3=true;
          //        复核通过    整改人对整改结果进行确认
            console.log(this.row.review_rectificationplan_state[0])
            console.log(this.row.review_rectificationplan_state[1]);
            this.step2 =false;
            this.step4 =false;
            this.row.rectification_results_input[0]=1;
//        复核通过    整改人对整改结果进行确认
        }else if(this.row.compile_rectificationplan_state[0]){

        }else{

        }
      },
      toggleAdpaIdentify(index,flag){
        this.tableData.forEach((el,ind)=>{
          if(index == ind ){
            if(flag==1){
              el.defect_state = "2"
            }else{
              el.defect_state = "1"
            }
          }
        })
        console.log(index)
      },
      toggleAdpaIdentifyshenhe(index,flag,clickIndex){
        var tempData =this.tableData[index]
        this.tableData.forEach((el,ind)=>{
          if(index == ind ){
            if(flag==1){
              el.rectification_state[clickIndex] = "2"
            }else{
              el.rectification_state[clickIndex]  = "1"
            };
            tempData.rectification_state =el.rectification_state;
            this.$set(this.tableData,index,tempData)
          }
        });
        console.log(this.tableData[index])
      },
      toggleAdpaIdentifycomment(index,flag,clickIndex){
        var tempData =this.tableData[index]
        this.tableData.forEach((el,ind)=>{
          if(index == ind ){
            if(flag==1){
              el.def_rec_state[clickIndex] = "2"
            }else{
              el.def_rec_state[clickIndex]  = "1"
            };
            console.log(tempData)
            tempData.def_rec_state =el.def_rec_state;
            this.$set(this.tableData,index,tempData)
          }
        });
        console.log(this.tableData[index])
      },
      saveBtn(){
        let that =this;
        if(!this.row){
          this.$alert('暂无可以保存的数据','提示');
          return false;
        }
        //数据保存
        //判断当前的数据是一条还是两条
        if(this.row.compile_rectificationplan_state.length=1){
          console.log('当前只有一条数据');
          console.log(this.row.rectification_state);
          console.log(this.row);
//          alert(this.row.rectification_state[0])
          if(this.row.task_allocation_state==1){
            //第一部整改任务分配已经完成 此项在第二项任务编制整改计划  实施前是可以修改的 但是不会影响task_allocation_state值
            //编制整改部分 判断是否完成
            //第二步的编制整改的判断
            console.log(this.row.rectification_state);
            console.log(!this.step4)
            console.log(this.step2)
            console.log((this.row.mend_principal[0].id==this.user_id||((this.row.rectification_results_input[0]!=1))))
            if(!this.step4 &&this.step2&&(this.row.mend_principal[0].id==this.user_id||((this.row.rectification_results_input[0]!=1)))){
              if(this.row.rectification_state[0]==1||this.row.rectification_state[0]==2){
                //尚未执行整改结果
                console.log(this.row.compile_rectificationresult_state[0]);
                console.log(this.row);
                if(this.row.section_principal_id==this.user_id||this.row.guidance_id==this.user_id){
                  if(this.row.compile_rectificationresult_state[0]==0){
                    this.axios.put('/api/v1/flaw/reviewrectificationplan/'+`${this.row.dere_id}`,{
                      rectification_type:[this.defect_source.indexOf(this.row.defect_source[0])*1+1],
                      rectification_state:[this.row.rectification_state[0]],
                      dere_id:this.row.dere_id
                    })
                      .then((res)=>{
                        if(res.data.code==0){
                          if(this.row.rectification_state[0]==2){
                            this.message[0]={
                              mess_receiver:this.tableData[this.row.index].mend_principal[0].id,
                              mess_type:11,
                              mess_link:'/defectFixed'
                            };
                            this.oaMessage[0]={
                              mess_receiver:this.tableData[this.row.index].mend_principal[0].uname,
                              mess_type:11,
                              mess_link:'/defectFixed'
                            };
                          }else{
                            this.message[0]={
                              mess_receiver:this.tableData[this.row.index].mend_principal[0].id,
                              mess_type:14,
                              mess_link:'/defectFixed'
                            };
                            this.oaMessage[0]={
                              mess_receiver:this.tableData[this.row.index].mend_principal[0].uname,
                              mess_type:14,
                              mess_link:'/defectFixed'
                            };
                          }
                          this.$alert('操作成功','提示');
                          this.disabled =0;
                          this.tableData[this.rowIndex].disabled =0;
                          this.tableData[this.rowIndex].reason_analysis =0;
                          this.tableData[this.rowIndex].reCheck =0;
                          this.step1=true;
                          this.step2=false;
                          this.step3=false;
                          this.step4=true;
                          this.step5=false;
                          this.putMessage(this.message);
                          this.putOAmessage(this.oaMessage);
                          this.initData(this.page);
                        }else{
                          this.$alert(res.data.message,'提示')
                        }
                      })
                  }else{
                    if(this.row.mend_principal[0].id==this.user_id){
                      //用户身份检测
                      //编制整改计划
                      this.axios.put('/api/v1/flaw/compilerectificationplan/'+`${this.row.dere_id}`,{
                        defect_reason_analysis:[this.row.defect_reason_analysis[0]],
                        rectification_measures:[this.row.rectification_measures[0]],
                        evaluation_finishtime:[parseInt(new Date((this.row.evaluation_finishtime[0])).getTime()/1000)],
                        dere_id:this.row.dere_id,
                        rectification_type:this.row.rectification_type
                      })
                        .then((res)=>{
                          if(res.data.code==0){
                            this.$alert(res.data.message,'提示');
                            this.disabled =0;
                            this.step1=true;
                            this.step2=false;
                            this.step3=false;
                            this.step4=true;
                            this.step5=false;
                            //编制整改部分完成 需要给部门负责人或具有责任标识的人发送复核检查消息通知
                            console.log("编制整改部分完成 需要给部门负责人或具有责任标识的人发送复核检查消息通知");
                            if(this.row.section_principal_id ==this.row.mend_principal[0].id){
                              console.log('需要知道责任标识负责人为复核审查人员 ');
                              this.message[0]={
                                mess_receiver:this.tableData[this.row.index].guidance_id,
                                mess_type:13,
                                mess_link:'/defectFixed'
                              };

                              this.oaMessage[0]={
                                mess_receiver:this.tableData[this.row.index].guidance_name,
                                mess_type:13,
                                mess_link:'/defectFixed'
                              };
                            }else{
                              this.message[0]={
                                mess_receiver:this.tableData[this.row.index].section_principal_id,
                                mess_type:13,
                                mess_link:'/defectFixed'
                              };
                              this.oaMessage[0]={
                                mess_receiver:this.tableData[this.row.index].section_principal_uname,
                                mess_type:13,
                                mess_link:'/defectFixed'
                              };
                            }
                            this.tableData[this.rowIndex].disabled =0;
                            this.tableData[this.rowIndex].reason_analysis =0;
                            this.tableData[this.rowIndex].reCheck =0;
                            this.putMessage(this.message);
                            this.putOAmessage(this.oaMessage);
                            this.initData(this.page);
                            return false;
                          }else{
                            this.$alert(res.data.message,'提示')
                          }
                        })
                    }
                  }
                }else{
                  if(this.row.compile_rectificationresult_state[0]==0&&this.row.rectification_state[0]==2){
                    if(this.row.mend_principal[0].id==this.user_id){
                      //用户身份检测
                      //编制整改计划
                      this.axios.put('/api/v1/flaw/compilerectificationplan/'+`${this.row.dere_id}`,{
                        defect_reason_analysis:[this.row.defect_reason_analysis[0]],
                        rectification_measures:[this.row.rectification_measures[0]],
                        evaluation_finishtime:[parseInt(new Date((this.row.evaluation_finishtime[0])).getTime()/1000)],
                        dere_id:this.row.dere_id,
                        rectification_type:this.row.rectification_type
                      })
                        .then((res)=>{
                          if(res.data.code==0){
                            this.$alert(res.data.message,'提示');
                            this.disabled =0;
                            this.step1=true;
                            this.step2=false;
                            this.step3=false;
                            this.step4=true;
                            this.step5=false;
                            //编制整改部分完成 需要给部门负责人或具有责任标识的人发送复核检查消息通知
                            console.log("编制整改部分完成 需要给部门负责人或具有责任标识的人发送复核检查消息通知");
                            if(this.row.section_principal_id ==this.row.mend_principal[0].id){
                              console.log('需要知道责任标识负责人为复核审查人员 ');
                              this.message[0]={
                                mess_receiver:this.tableData[this.row.index].guidance_id,
                                mess_type:13,
                                mess_link:'/defectFixed'
                              };

                              this.oaMessage[0]={
                                mess_receiver:this.tableData[this.row.index].guidance_name,
                                mess_type:13,
                                mess_link:'/defectFixed'
                              };
                            }else{
                              this.message[0]={
                                mess_receiver:this.tableData[this.row.index].section_principal_id,
                                mess_type:13,
                                mess_link:'/defectFixed'
                              };
                              this.oaMessage[0]={
                                mess_receiver:this.tableData[this.row.index].section_principal_uname,
                                mess_type:13,
                                mess_link:'/defectFixed'
                              };
                            }
                            this.tableData[this.rowIndex].disabled =0;
                            this.tableData[this.rowIndex].reason_analysis =0;
                            this.tableData[this.rowIndex].reCheck =0;
                            this.putMessage(this.message);
                            this.putOAmessage(this.oaMessage);
                            this.initData(this.page);
                            return false;
                          }else{
                            this.$alert(res.data.message,'提示')
                          }
                        })
                    }
                  }
                }
                //复核整改完全已完成
              }else {
//                alert(45)
                //复核整改有部分未完成或者为拒绝状态
                if(this.row.mend_principal[0].id==this.user_id){
                  //用户身份检测
                  //编制整改计划
                  this.axios.put('/api/v1/flaw/compilerectificationplan/'+`${this.row.dere_id}`,{
                    defect_reason_analysis:[this.row.defect_reason_analysis[0]],
                    rectification_measures:[this.row.rectification_measures[0]],
                    evaluation_finishtime:[parseInt(new Date((this.row.evaluation_finishtime[0])).getTime()/1000)],
                    dere_id:this.row.dere_id,
                    rectification_type:this.row.rectification_type
                  })
                    .then((res)=>{
                      if(res.data.code==0){
                        this.$alert(res.data.message,'提示');
                        this.disabled =0;
                        this.step1=true;
                        this.step2=false;
                        this.step3=false;
                        this.step4=true;
                        this.step5=false;
                        //编制整改部分完成 需要给部门负责人或具有责任标识的人发送复核检查消息通知
                        console.log("编制整改部分完成 需要给部门负责人或具有责任标识的人发送复核检查消息通知");
                        if(this.row.section_principal_id ==this.row.mend_principal[0].id){
                          console.log('需要知道责任标识负责人为复核审查人员 ');
                          this.message[0]={
                            mess_receiver:this.tableData[this.row.index].guidance_id,
                            mess_type:13,
                            mess_link:'/defectFixed'
                          };

                          this.oaMessage[0]={
                            mess_receiver:this.tableData[this.row.index].guidance_name,
                            mess_type:13,
                            mess_link:'/defectFixed'
                          };
                        }else{
                          this.message[0]={
                            mess_receiver:this.tableData[this.row.index].section_principal_id,
                            mess_type:13,
                            mess_link:'/defectFixed'
                          };
                          this.oaMessage[0]={
                            mess_receiver:this.tableData[this.row.index].section_principal_uname,
                            mess_type:13,
                            mess_link:'/defectFixed'
                          };
                        }
                        this.tableData[this.rowIndex].disabled =0;
                        this.tableData[this.rowIndex].reason_analysis =0;
                        this.tableData[this.rowIndex].reCheck =0;
                        this.putMessage(this.message);
                        this.putOAmessage(this.oaMessage);
                        this.initData(this.page);
                        return false;
                      }else{
                        this.$alert(res.data.message,'提示')
                      }
                    })
                }
              }
            }else if((this.row.section_principal_id==this.user_id||this.row.guidance_id==this.user_id)
              &&(this.row.compile_rectificationplan_state[0]==1
              &&
              this.row.review_opinions==1&&this.row.reCheck==1
              &&this.step3)&&!this.step5){
              console.log('执行复核整改');
              if(this.row.review_rectificationplan_state[0]==this.row.rectification_state[0]
                &&this.row.review_rectificationplan_state[0]!=0){
                console.log('nothing change');
                this.$alert('复核成功','提示');
                this.disabled =0;
                this.tableData[this.rowIndex].disabled =0;
                this.tableData[this.rowIndex].reason_analysis =0;
                this.tableData[this.rowIndex].reCheck =0;
                this.step1=true;
                this.step2=false;
                this.step3=false;
                this.step4=true;
                this.step5=false;
              }else{
                if(this.row.rectification_state[0]==0){
                  this.$alert('请复核整改计划','提示');
                  return false;
                }
                this.axios.put('/api/v1/flaw/reviewrectificationplan/'+`${this.row.dere_id}`,{
                  rectification_type:[this.defect_source.indexOf(this.row.defect_source[0])*1+1],
                  rectification_state:[this.row.rectification_state[0]],
                  dere_id:this.row.dere_id
                })
                  .then((res)=>{
                    if(res.data.code==0){
                      if(this.row.rectification_state[0]==2){
                        this.message[0]={
                          mess_receiver:this.tableData[this.row.index].mend_principal[0].id,
                          mess_type:11,
                          mess_link:'/defectFixed'
                        };
                        this.oaMessage[0]={
                          mess_receiver:this.tableData[this.row.index].mend_principal[0].uname,
                          mess_type:11,
                          mess_link:'/defectFixed'
                        };
                      }else{
                        this.message[0]={
                          mess_receiver:this.tableData[this.row.index].mend_principal[0].id,
                          mess_type:14,
                          mess_link:'/defectFixed'
                        };
                        this.oaMessage[0]={
                          mess_receiver:this.tableData[this.row.index].mend_principal[0].uname,
                          mess_type:14,
                          mess_link:'/defectFixed'
                        };
                      }
                      this.$alert('复核成功','提示');
                      this.disabled =0;
                      this.tableData[this.rowIndex].disabled =0;
                      this.tableData[this.rowIndex].reason_analysis =0;
                      this.tableData[this.rowIndex].reCheck =0;
                      this.step1=true;
                      this.step2=false;
                      this.step3=false;
                      this.step4=true;
                      this.step5=false;
                      this.putMessage(this.message);
                      this.putOAmessage(this.oaMessage);
                      this.initData(this.page);
                    }else{
                      this.$alert(res.data.message,'提示')
                    }
                  })
              }
            }else if(this.row.has_analysis==1&&!this.step4) {
              //第四步和第五步区别开来

              if(this.row.rectification_results[0]&&this.row.def_rec_state[0]!=0){
                //整改已经完成且还未确认  走第五步

                if(this.row.review_opinions==1&&this.user_id==this.row.evaluator_id&&this.row.reCheck==1&&this.step5){
                  if(this.row.compile_rectificationresult_state[0]==1){
                    this.message[0]={
                      mess_receiver:this.tableData[this.row.index].section_principal_id,
                      mess_type:14,
                      mess_link:'/defectFixed'
                    };
                    this.oaMessage[0]={
                      mess_receiver:this.tableData[this.row.index].section_principal_uname,
                      mess_type:14,
                      mess_link:'/defectFixed'
                    };
                  }
                  this.axios.put('/api/v1/flaw/implementrectificationresult/'+`${this.row.dere_id}`,{
                    rectification_type:[this.defect_source.indexOf(this.row.defect_source[0])*1+1],
                    def_rec_state:[this.row.def_rec_state[0]],
                    implementation_opinions:[this.row.implementation_opinions[0]],
                  })
                    .then((res)=>{
                      if(res.data.code==0){
                        this.$alert(res.data.message,'提示');
                        this.disabled =0;
                        this.step1=true;
                        this.step2=false;
                        this.step3=false;
                        this.step4=true;
                        this.step5=false;
                        this.tableData[this.rowIndex].disabled =0;
                        this.tableData[this.rowIndex].reason_analysis =0;
                        this.tableData[this.rowIndex].reCheck =0;
                        console.log(this.message)
                        this.putMessage(this.message);
                        this.initData(this.page);
                      }else{
                        this.$alert(res.data.message,'提示')
                      }
                    })
                }else if(this.row.rectification_state==1&&!this.row.implement_rectificationresult_state[0]){
                    //第五步落实整改确认被打回需要从第四步重新开始确认
                  //执行到第四步 落实整改
                  console.log('执行第四步');
                  if(this.row.rectification_results_input[0]==1){
                    this.message[0]={
                      mess_receiver:this.tableData[this.row.index].evaluator_id,
                      mess_type:2,
                      mess_link:'/defectFixed'
                    };
                    this.oaMessage[0]={
                      mess_receiver:this.tableData[this.row.index].evaluator_uname,
                      mess_type:2,
                      mess_link:'/defectFixed'
                    };
                  }
                  this.axios.put('/api/v1/flaw/compilerectificationresult/'+`${this.row.dere_id}`,{
                    rectification_results:[this.row.rectification_results[0]],
                    reasons_measures:[this.row.reasons_measures[0]],
                    rectification_type:this.row.rectification_type
                  })
                    .then((res)=>{
                      if(res.data.code==0){
                        this.$alert(res.data.message,'提示');
                        this.disabled =0;
                        this.step1=true;
                        this.step2=false;
                        this.step3=false;
                        this.step4=true;
                        this.step5=false;
                        this.tableData[this.rowIndex].disabled =0;
                        this.tableData[this.rowIndex].reason_analysis =0;
                        this.tableData[this.rowIndex].reCheck =0;
                        this.putMessage(this.message);
                        this.putOAmessage(this.oaMessage);
                        this.initData(this.page);
                      }else{
                        this.$alert(res.data.message,'提示')
                      }
                    })
                }
              }else{
//                this.row.review_opinions==1&&this.user_id==this.row.evaluator_id&&this.row.reCheck==1&&this.step5
                //执行到第四步 落实整改
                console.log('执行第四步');
                if(this.row.rectification_results_input[0]==1){
                  this.message[0]={
                    mess_receiver:this.tableData[this.row.index].evaluator_id,
                    mess_type:2,
                    mess_link:'/defectFixed'
                  };
                  this.oaMessage[0]={
                    mess_receiver:this.tableData[this.row.index].evaluator_uname,
                    mess_type:2,
                    mess_link:'/defectFixed'
                  };
                }
                this.axios.put('/api/v1/flaw/compilerectificationresult/'+`${this.row.dere_id}`,{
                  rectification_results:[this.row.rectification_results[0]],
                  reasons_measures:[this.row.reasons_measures[0]],
                  rectification_type:this.row.rectification_type
                })
                  .then((res)=>{
                    if(res.data.code==0){
                      this.$alert(res.data.message,'提示');
                      this.disabled =0;
                      this.step1=true;
                      this.step2=false;
                      this.step3=false;
                      this.step4=true;
                      this.step5=false;
                      this.tableData[this.rowIndex].disabled =0;
                      this.tableData[this.rowIndex].reason_analysis =0;
                      this.tableData[this.rowIndex].reCheck =0;
                      this.putMessage(this.message);
                      this.putOAmessage(this.oaMessage);
                      this.initData(this.page);
                    }else{
                      this.$alert(res.data.message,'提示')
                    }
                  })
              }

            }else if(this.row.review_opinions==1&&this.user_id==this.row.evaluator_id&&this.row.reCheck==1&&this.step5){
              console.log('执行第五步');
              console.log(this.row);
              if(this.row.implement_rectificationresult_state[0]){
                  //第五步没有做取消操作
                //第五步完成
                console.log('流程完成向责任部门负责人发送完成消息')
                if(this.row.compile_rectificationresult_state[0]==1){
                  this.message[0]={
                    mess_receiver:this.tableData[this.row.index].section_principal_id,
                    mess_type:14,
                    mess_link:'/defectFixed'
                  };
                  this.oaMessage[0]={
                    mess_receiver:this.tableData[this.row.index].section_principal_uname,
                    mess_type:14,
                    mess_link:'/defectFixed'
                  };
                }
                this.axios.put('/api/v1/flaw/implementrectificationresult/'+`${this.row.dere_id}`,{
                  rectification_type:[this.defect_source.indexOf(this.row.defect_source[0])*1+1],
                  def_rec_state:[this.row.def_rec_state[0]],
                  implementation_opinions:[this.row.implementation_opinions[0]],
                })
                  .then((res)=>{
                    if(res.data.code==0){
                      this.$alert(res.data.message,'提示');
                      this.disabled =0;
                      this.step1=true;
                      this.step2=false;
                      this.step3=false;
                      this.step4=true;
                      this.step5=false;
                      this.tableData[this.rowIndex].disabled =0;
                      this.tableData[this.rowIndex].reason_analysis =0;
                      this.tableData[this.rowIndex].reCheck =0;
                      console.log(this.message)
                      this.putMessage(this.message);
                      this.initData(this.page);
                    }else{
                      this.$alert(res.data.message,'提示')
                    }
                  })
              }else if(this.row.implement_rectificationresult_state[0]==0){
                console.log('没有完成向第四步发消息');
                if(this.row.compile_rectificationresult_state[0]==1){
                  this.message[0]={
                    mess_receiver:this.tableData[this.row.index].mend_principal[0].id,
                    mess_type:15,
                    mess_link:'/defectFixed'
                  };
                  this.oaMessage[0]={
                    mess_receiver:this.tableData[this.row.index].mend_principal[0].uname,
                    mess_type:15,
                    mess_link:'/defectFixed'
                  };
                }
                this.axios.put('/api/v1/flaw/implementrectificationresult/'+`${this.row.dere_id}`,{
                  rectification_type:[this.defect_source.indexOf(this.row.defect_source[0])*1+1],
                  def_rec_state:[this.row.def_rec_state[0]],
                  implementation_opinions:[this.row.implementation_opinions[0]],
                })
                  .then((res)=>{
                    if(res.data.code==0){
                      this.$alert(res.data.message,'提示');
                      this.disabled =0;
                      this.step1=true;
                      this.step2=false;
                      this.step3=false;
                      this.step4=true;
                      this.step5=false;
                      this.tableData[this.rowIndex].disabled =0;
                      this.tableData[this.rowIndex].reason_analysis =0;
                      this.tableData[this.rowIndex].reCheck =0;
                      console.log(this.message)
                      this.putMessage(this.message);
                      this.putOAmessage(this.oaMessage);
                      this.initData(this.page);
                    }else{
                      this.$alert(res.data.message,'提示')
                    }
                  })
              }


            }else{
            }
          }else {
            console.log('责任部门主管的第一步操作');
            if(this.row.section_principal_id ==this.user_id){
              var arr=[];
              for(var i in this.tableData){
                if(this.tableData[i].disabled=="1"){
                  arr[0]=this.tableData[i].mend_principal[0].id;
                  if(!arr[0]){
                    this.$alert('请选择整改人','提示');
                    return false;
                  }
                  this.message[0]={
                    mess_receiver:this.tableData[i].mend_principal[0].id,
                    mess_type:10,
                    mess_link:'/defectFixed'
                  };

                  this.oaMessage[0]={
                    mess_receiver:this.tableData[i].mend_principal[0].uname,
                    mess_type:10,
                    mess_link:'/defectFixed'
                  };


                  if(this.tableData[i].defect_state==0){
                    this.$alert('请确认缺陷','提示');
                    return false;
                  }
                  this.axios.put('/api/v1/flaw/defectrectification/'+`${this.tableData[i].dere_id}`,{
                    defect_state:this.tableData[i].defect_state,
                    rectification_type:this.tableData[i].rectification_type,
                    defect_principal:arr,
                    communication_ideas:this.tableData[i].communication_ideas,
                    dere_id:this.tableData[i].dere_id
                  }).then((res)=>{
                    this.disabled =0;
                    this.tableData[this.rowIndex].disabled =0;
                    this.step1=true;
                    this.step2=false;
                    this.step3=false;
                    this.step4=true;
                    this.step5=false;
                    this.$alert(res.data.message,'提示');
                    this.putMessage(this.message);
                    this.putOAmessage(this.oaMessage);
                    this.initData(this.page);
                    console.log(that.oaMessage)
                  })
                  return false;
                }
              }
            }
          }

        }
      },
      //整改负责人
      confirmEditor(form){
        //评价人员和审核人员分开
        this.formMenber =this.tableData2[this.changeIndex];
        console.log(this.changeIndex)
        console.log(this.clickIndex);
        console.log(this.tableData)
        if(this.tableData2[this.changeIndex]==undefined){
          this.$alert('请选择相关人员','提示');
          return false
        };
        if(this.clickIndex==0){
          this.tableData[this.rowIndex].mend_principal[0]={
            name:this.tableData2[this.changeIndex].real_name,
            id:this.tableData2[this.changeIndex].user_id,
            user_name:this.tableData2[this.changeIndex].user_name
          };
          this.mend_principal[this.clickIndex]={
            name:this.tableData2[this.changeIndex].real_name,
            id:this.tableData2[this.changeIndex].user_id,
            user_name:this.tableData2[this.changeIndex].user_name
          };
          this.mend_principal[1] =this.tableData[this.rowIndex].mend_principal[1];
        }else if(this.clickIndex==1){
          if(!this.tableData[this.rowIndex].mend_principal[0].name){
            this.mend_principal[0].name ='设计评价整改'
          }
          this.mend_principal[0]={
            name: this.tableData[this.rowIndex].mend_principal[0].name,
            id:this.tableData[this.rowIndex].mend_principal[0].id,
            user_name:this.tableData[this.rowIndex].mend_principal[0].user_name
          }
          this.mend_principal[this.clickIndex]={
            name:this.tableData2[this.changeIndex].real_name,
            id:this.tableData2[this.changeIndex].user_id,
            user_name:this.tableData2[this.changeIndex].user_name
          };
          this.tableData[this.rowIndex].mend_principal[0] =this.tableData2[this.changeIndex];
        }
        this.$set(this.tableData[this.rowIndex],'mend_principal',this.mend_principal);
        this.mend_principal =[];
        this.dialogFormVisible3 =false;
        console.log( this.tableData[this.rowIndex])
      },
      putMessage(message){
        this.axios.post('/api/v1/accout/usermessagebatch',{
          total_messages:message
        }).then((res)=>{
          if(res.data.code==0){
            console.log('消息发布成功');
            message=[];
          }
        })
      },
      putOAmessage(message){
        this.axios.post('/api/v1/accout/externalmessagebatch',{
          total_messages:message
        }).then((res)=>{
          console.log(res.data)
        })
      },
      changeSwitch(index,value){
        this.changeIndex=index;
        for(var i in this.tableData2){
          this.tableData2[i].isActive ="0";
        };
        this.tableData2[index].isActive ="1";
        this.$set(this.tableData2[index],"isActive","1");
      },
      //缺陷整改责任人列表人员
      showFormMenbertrue(row,flag,rowIndex,index){
        this.clickIndex =index;
        this.row =row;
        console.log(index)
        console.log(row);
        this.dialogFormVisible3=true;
        this.rowIndex =rowIndex;

        this.getMenber(row.dere_id);

      },
      getMenber(id){

        this.axios.get('/api/v1/flaw/defectrectification/'+`${id}`)
          .then((res)=>{
            if(res.data.code==0){
              for(var i in res.data.data){
                res.data.data[i].isActive="0"
              }
              this.tableData2=res.data.data;

            }
            console.log(this.tableData2)
          }).catch((res)=>{
          console.log(res)
          this.$alert(res)
        })
      },
      tableRowClassName2 ({row, rowIndex}) {
        //把每一行的索引放进row
        row.index = rowIndex;
        if((row.implement_rectificationresult_state.length==1&&row.implement_rectificationresult_state[0]==1)
          ||(row.implement_rectificationresult_state[0]==1&&row.implement_rectificationresult_state[1]==1)){
          return 'has-finished';
        }

      },
      tableRowClassName ({row, rowIndex}) {
        //把每一行的索引放进row
        row.index = rowIndex;
      },
      cell({row, column, rowIndex, columnIndex}) {
        //第八列添加 red 类
        if (columnIndex == 1) {
          return "first-table-clouum"
        }
        if (columnIndex == 11||columnIndex==17||columnIndex==20) {
          return 'walk_through'
        }
        if (columnIndex == 12) {
          return 'defect_states'
        }
        if(columnIndex == 14||columnIndex==15||columnIndex==18||columnIndex==19||columnIndex==21){
          return 'mend_principal'
        }
        if(columnIndex == 16){
          return 'datePicker'
        };
      },
      //穿行测试切换
      toggleWalkThrough(row){
        console.log(row);
        this.rowIndex =row.index;
        this.dialogFormVisible =true;
      },
      initData(page){
        this.axios.get('/api/v1/flaw/defectrectificationvertical',{
          params:{
            limit:10,
            page:page,
          }
        })
          .then((res)=>{
            if(res.data.code==0){
              this.loading =false;
              for(var i in res.data.data){
                res.data.data[i].disabled ="0";
                res.data.data[i].reason_analysis =0;
                res.data.data[i].defect_reason=[];
                res.data.data[i].rectification_resul =0;
                res.data.data[i].reCheck=0;
                res.data.data[i].review_opinions=1;
                res.data.data[i].has_analysis =0;
                res.data.data[i].rectification_results_input=[];
                res.data.data[i].confirm_resuklt =0;
                res.data.data[i].confirm_result=[];
                for(var k in res.data.data[i].evaluation_finishtime){
                  res.data.data[i].evaluation_finishtime[k] =formatDateTime(res.data.data[i].evaluation_finishtime[k]);
                }
                if(res.data.data[i].defect_source.length==2){
                  res.data.data[i].mend_principal[0].name = res.data.data[i].mend_principal[0].name||'设计评价整改';
                  res.data.data[i].mend_principal[1].name = res.data.data[i].mend_principal[1].name||'执行评价整改';
                }else if(res.data.data[i].defect_source.length==1&&res.data.data[i].defect_source=='设计缺陷'){
                  res.data.data[i].mend_principal[0].name = res.data.data[i].mend_principal[0].name||'设计评价整改';
                }else if(res.data.data[i].defect_source.length==1&&res.data.data[i].defect_source=='执行缺陷'){
                  res.data.data[i].mend_principal[0].name = res.data.data[i].mend_principal[0].name||'执行评价整改';
                }
              }
              this.tableData =res.data.data;
              console.log(this.tableData);
              this.total = res.data.pagination.total
              this.pageSize =res.data.pagination.pages;
              this.currentPage=parseInt(res.data.pagination.page)
            }
          })
      },

    },
    mounted(){
      this.initData(this.page);
      console.log(this.height)
    },
    created(){
//        this.getMenber();
    },
  })
</script>

<style scoped="">
  .defectFixedIndex{
    width: 100%;
    height: 100%;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    padding: 10px;
  }
  .defectFixedIndex >>> .el-table{
    border: 1px solid #aac983;
  }
  .defectFixedIndex >>> .el-table thead th.is-leaf .cell{
    font-size: 14px;
  }
  .defectFixedIndex .mend_principal .cell .mend_principal_scope .mend_principal_cell{
    /*text-decoration: underline;*/
    color: #4479bf;
  }
  .defectFixedIndex >>> .mend_principal_scope{
    margin-left: -10px;
    margin-right: -10px;
  }
  .defectFixedIndex >>> .mend_principal_scope .mend_principal_cell .el-textarea{
    padding:  0 3px;
  }
  .defectFixedIndex >>> .mend_principal_scope .mend_principal_cell .el-textarea__inner{
    padding: 2px 2px;
  }
  .defectFixedIndex >>> .mend_principal_scope .mend_principal_cell .el-textarea__inner .el-input__icon{
    position: absolute;
    right: 25px;
  }
  .defectFixedIndex >>> .cell textarea{
    width: 100%;
    height: auto;
  }
  .defectFixedIndex >>> .cell .el-input{
    width: auto;
  }
  .defectFixedIndex >>> .cell .el-input__inner{
    border: 0;
    background: none;
    padding: 0;
    width: 100%;
  }
  .defectFixedIndex >>> .datePicker .cell .el-input__inner{
    padding-left: 20px;
  }

  .defectFixedIndex >>> .datePicker .cell .el-input__inner .el-input__prefix{
    width: 15px;
    left: -3px;
  }
  .defectFixedIndex >>> .cell .mend_principal_scope .hasOne{
    line-height: 18px;
    font-size: 12px;
  }
  .defectFixedIndex >>> .cell .mend_principal_scope .hasTwo{
    height: 55px;
    line-height: 1;
  }
  .defectFixedIndex >>> .cell .mend_principal_scope .hasOne{
    /*padding-bottom: 10px;*/
  }
  .defectFixedIndex >>> .cell .mend_principal_scope .hasTwo:nth-child(1){
    padding-bottom: 10px;
    position: relative;

  }
  .defectFixedIndex >>> .cell .mend_principal_scope .hasTwo div{
    /*height: 55px;*/
  }
  .defectFixedIndex >>> .cell .mend_principal_scope  .el-input__inner{
    height: 55px;
  }
  .defectFixedIndex >>> .cell .mend_principal_scope .hasTwo:nth-child(2){
    padding-top: 10px;
  }
  .defectFixedIndex >>> .cell .mend_principal_scope .hasTwo:nth-child(1):after{
    position: absolute;
    content: '';
    left: 0;
    height: 1px;
    bottom:0;
    background: #aac983;
    width: 100%;
  }
  .defectFixedIndex >>> .cell .mend_principal_scope .hasTwo:nth-child(2):after{
    position: absolute;
    content: '';
    left: 0;
    height: 1px;
    top:-1px;
    background: #aac983;
    width: 100%;
  }
  .defectFixedIndex >>>  .el-dialog{
    width: 400px;
  }
  .defectFixedIndex >>>  .el-dialog .el-dialog__body{
    padding: 10px 8px;
  }
  .defectFixedIndex >>>  .dialog-footer .el-button{
    padding: 10px 16px;
    margin-top: 10px;
    /*background: #8cc34b;*/
  }
  .defectFixedIndex >>>  .dialog-footer{
    text-align: right;
  }
  .defectFixedIndex >>> .defect_state .el-form-item__label{
    /*width: 100px;*/
  }

  .defectFixedIndex >>> .defect_state .el-dialog{
    width: 520px;
  }
  .defectFixedIndex >>> .defect_states .el-textarea__inner{
    padding: 1px 1px;
  }
  .defectFixedIndex >>> .defect_states .cell{
    padding: 2px 2px;
  }
  .defectFixedIndex >>> .navList  .blockBg{
    float: right;
    background: white;
  }
  .defectFixedIndex >>> .navList  .blockBg  .blockBgDiv{
    float: left;

  }
  .defectFixedIndex >>> .navList  .blockBg  .blockBgDiv span{
    display: inline-block;
    width: 18px;
    height: 18px;
    background: yellow;
    border-radius: 1px;
  }
  .defectFixedIndex >>> .navList  .blockBg   .hasFinished  {
    color: yellow;
    vertical-align: top;
  }
  .custmerTips{
    float: right;
  }
  .defectFixedIndex >>> .navList .custmerTips{
    background: none;
  }
  .defectFixedIndex >>> .navList .custmerTips li{
    margin-right: 5px;
  }
  .defectFixedIndex >>> .navList .custmerTips li b{
    font-weight: normal;
    display: inline-block;
    vertical-align: top;

  }
  .defectFixedIndex >>> .navList .custmerTips li span{
    background: #fff;
    cursor: pointer;
    width: 18px;
    height: 18px;
    display: inline-block;
    position: relative;
    border: 1px solid #ccc;
    border-radius: 2px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
  }
  .defectFixedIndex >>> .navList .custmerTips li span.hasDone{
    background: #f56c6c;
    border: 1px solid #f56c6c;
  }
  .defectFixedIndex >>> .navList .custmerTips li span.permissed{
    background: #8bc34a;
    border: 1px solid #8bc34a;
  }

  .defectFixedIndex >>> .navList .custmerTips li span.notAllowed{
    background: #ccc;
    border: 1px solid #c0c4cc;
  }
  .defectFixedIndex >>> .navList .custmerTips li span.noControllerPoint{
    background: #ffa800;
    border: 1px solid #ffa800;
  }
  .defectFixedIndex >>> .navList .custmerTips li span.notAllowModify{
    background: #d77438;
    border: 1px solid #d77438;
  }
  .defectFixedIndex >>> .navList .custmerTips li span:after{
    top: 2px;
    left: 6px;
    width: 4px;
    height: 8px;
    -webkit-transform: rotate(45deg) scaleY(1);
    transform: rotate(45deg) scaleY(1);
    -webkit-box-sizing: content-box;
    box-sizing: content-box;
    content: "";
    border: 1px solid #fff;
    border-left: 0;
    border-top: 0;
    position: absolute;
    -webkit-transition: -webkit-transform .15s ease-in .05s;
    transition: -webkit-transform .15s ease-in .05s;
    transition: transform .15s ease-in .05s;
    transition: transform .15s ease-in .05s, -webkit-transform .15s ease-in .05s;
    -webkit-transform-origin: center;
    transform-origin: center;
  }
  .defectFixedIndex >>> .navList .custmerTips li span.notAllowed:after{
    width: 0;
    height: 0;
    border-color: #ccc;
  }
  .defectFixedIndex >>> .navList .custmerTips li span.noControllerPoint:after{
    width: 0;
    height: 0;
    border-color: #ffa800;
  }
  /*已完成*/
  .defectFixedIndex .e-operCheck .hasbl_evaluation .has_finished{
    background: #f56c6c;
    border: 1px solid #f56c6c;
  }
  .defectFixedIndex >>> .navList .custmerTips ul li{
    float: left;
    color: #333;
  }
  .defectFixedIndex >>> .el-table .el-table__body  tr.has-finished .el-checkbox__input .el-checkbox__inner{
    background: #f56c6c;
    border-color: #f56c6c;
  }

  .defectFixedIndex >>> .el-table .el-table__body tr.has-finished  .el-checkbox__inner::after{
    left: 5px;
    width: 5px;
    height: 9px;
    top: 1px;
    -webkit-transform: rotate(45deg) scaleY(1);
    transform: rotate(45deg) scaleY(1);
    cursor: not-allowed;
  }
  .defectFixedIndex >>> .el-table .el-table__body  tr.has-finished  .el-checkbox{
    /*z-index: -1;*/
  }
  @media screen and (max-width: 1400px) {
    .defectFixedIndex{
      padding: 6px;
    }
  }
</style>
